# -- coding: utf-8 --

import os
import sys
sys.path.append('D:/pycharm/appium_unittest')
import HTMLTestRunner
import unittest
#from BeautifulReport import BeautifulReport
import threading
import multiprocessing #进程
from util.server import Server
from appium import webdriver
from business.login_business import LoginBusiness
from business.login_businessB import LoginBusinessB
from util.write_user_command import WriteUserCommand
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
import time
from util.push_apk import BaseDriver
from util.dos_cmd import DosCmd


def get_devicesNum():
    server = Server()
    devicesNum = server.get_devices()
    Num = len(devicesNum)
    return Num

def list_devices():
    server = Server()
    devices = server.get_devices()
    print(devices)
    return devices

'''
 单进程安装
'''
def install_apk(apk_name):
    path = 'D:\\pycharm\\appium_unittest\\apk\\'
    dos_cmd = DosCmd()
    for i in list_devices():
        print('-----开始安装:'+i+'------')
        dos_cmd.excute_cmd_result('adb -s ' + i +' install ' +path+apk_name)
        print('-----安装完毕:' + i + '------')
        # print('adb -s ' + i +' install '+path+apk_name)

'''
 多线程安装 
'''
def threading_install(apk_name):
    # list = list_devices(n)
    path = 'D:\\pycharm\\appium_unittest\\apk\\'
    dos_cmd = DosCmd()
    print('-----开始安装:' + list_devices() + '------')
    dos_cmd.excute_cmd_result('adb -s ' + list_devices() + ' install ' + path + apk_name)
    print('-----安装完毕:' + list_devices() + '------')

install_apk('youbei-pre.apk')
def thread_num():
    threads = []
    for i in range(get_devicesNum()):
        t = threading.Thread(target=threading_install,args=('youbei-pro.apk',))
        threads.append(t)
    for j in threads:
        j.start()
        j.join()

thread_num()
# t1=threading.Thread(target=threading_install,args=(6,'youbei-pre.apk',0))
# t2=threading.Thread(target=threading_install,args=(6,'youbei-pre.apk',1))
# t3=threading.Thread(target=threading_install,args=(6,'youbei-pre.apk',2))
# t4=threading.Thread(target=threading_install,args=(6,'youbei-pre.apk',3))
# t5=threading.Thread(target=threading_install,args=(6,'youbei-pre.apk',4))
# t6=threading.Thread(target=threading_install,args=(6,'youbei-pre.apk',5))
#
# t1.start()
# t2.start()
# t3.start()
# t4.start()
# t5.start()
# t6.start()
#
# t1.join()
# t2.join()
# t3.join()
# t4.join()
# t5.join()
# t6.join()









